package com.dilean.impl.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.dilean.api.model.Attribute;
import com.dilean.api.model.AttributeList;
import com.dilean.api.model.AttributeType;


@Entity
@Table(name = "ATTRIBUTES")
public class AttributeImpl implements Attribute {

    @Id
    @Column(name = "ID")
    private Integer id;
    
    @Column(name = "NAME", unique = false, nullable = false)
    private String name;
    
    @Column(name = "DESCRIPTION", unique = false, nullable = true)
    private String description;
    
    @Column(name = "IS_MULTIPLE", unique = false, nullable = false)
    private boolean isMultiple;
    
    @ManyToOne(targetEntity = AttributeTypeImpl.class)
    @JoinColumn(name="TYPE_ID")
    private AttributeType attrType;
    
    @OneToOne(targetEntity = AttributeListImpl.class, cascade = CascadeType.ALL)
    @JoinColumn(name="LIST_ID")
    private AttributeList attrList;
    
	@Override
	public Integer getId() {
		return id;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setId(Integer id) {
		this.id = id;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public AttributeType getAttributeType() {
		return attrType;
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public boolean isMultiple() {
		return isMultiple;
	}

	@Override
	public AttributeList getAttributeList() {
		return attrList;
	}

	@Override
	public void setAttributeType(AttributeType attributeType) {
		this.attrType = attributeType;
	}

	@Override
	public void setDescription(String desc) {
		this.description = desc;
	}

	@Override
	public void setMultiple(boolean flag) {
		this.isMultiple= flag;
	}

	@Override
	public void setAttributeList(AttributeList attributeList) {
		this.attrList = attributeList;
	}
	
	@Override
	public String toString() {
		return "Attr[" + getName() + "]";
	}

}
